package second.codeTop.package2;

import util.ListNode;

/**
 * @ClassName LC21
 * @description:
 * @author: 荣燊
 * @create: 2022-04-03 15:05
 **/
public class LC21 {
    // 合并两个有序链表
    public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
        ListNode node = new ListNode();
        ListNode res = node;
        while (list1 != null & list2 != null) {
            ListNode temp = new ListNode();
            if (list1.val < list2.val) {
                temp = list1;
                list1 = list1.next;
            } else {
                temp = list2;
                list2 = list2.next;
            }
            node.next = temp;
            node = node.next;
        }
        if (list1 != null) {
            node.next = list1;
        }
        if (list2 != null) {
            node.next = list2;
        }
        return res.next;
    }
}
